package com.bloveoacom.weight;

import android.app.Dialog;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RadioGroup;
import android.widget.TextView;

import com.bloveoacom.weichi.R;


public class PayDialog extends Dialog implements View.OnClickListener, RadioGroup.OnCheckedChangeListener {
    private RadioGroup rbPayWay;
    private TextView tvPay;
    private ImageView ivClose;
    private ItemClickListener itemClickListener;
    private int payType;
    public static int PAYTYPE_ZHIFUBAO=1;
    public static int PAYTYPE_WEIXIN=2;

    public PayDialog(Context context, int theme) {
        super(context, theme);
    }



    public void setItemClickListener(ItemClickListener itemClickListener) {
        this.itemClickListener = itemClickListener;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.setContentView(R.layout.dialog_pay);
        //设置window背景，默认的背景会有Padding值，不能全屏。当然不一定要是透明，你可以设置其他背景，替换默认的背景即可。
        getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        //一定要在setContentView之后调用，否则无效
        getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        this.setCanceledOnTouchOutside(true);
        rbPayWay = (RadioGroup) findViewById(R.id.rg_pay_way);
        ivClose = (ImageView) findViewById(R.id.iv_close);
        //设置监听
        ivClose.setOnClickListener(this);
        tvPay = (TextView) findViewById(R.id.tv_pay);
        //设置监听
        rbPayWay.setOnCheckedChangeListener(this);
        tvPay.setOnClickListener(this);
        rbPayWay.check(R.id.rb_zhifubao);
        payType=PAYTYPE_ZHIFUBAO;

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.tv_pay:
                if (itemClickListener != null) {
                    dismiss();
                    itemClickListener.pay(payType);
                }
                break;
            case R.id.iv_close:
                dismiss();
                break;
            default:
                break;
        }
    }

    @Override
    public void onCheckedChanged(RadioGroup group, int checkedId) {
        switch (checkedId){
            case R.id.rb_zhifubao:
                payType=PAYTYPE_ZHIFUBAO;
                break;
            case R.id.rb_weizin:
                payType=PAYTYPE_WEIXIN;
                break;
            default:
                break;
        }
    }

    public interface ItemClickListener {
        void pay(int payType);
    }

}
